/*

 */
package com.ohos.connect.devicecloud.auth.core.util;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ohos.connect.devicecloud.auth.core.pojo.SaBaseClientLoginUser;
import com.ohos.connect.devicecloud.common.exception.CommonException;

import java.util.List;

/**
 * APP登录用户工具类
 *
 *
 **/
public class StpAppLoginUserUtil {

    /**
     * 获取当前APP登录用户
     **/
    public static SaBaseClientLoginUser getClientLoginUser() {
        return (SaBaseClientLoginUser) StpClientUtil.getTokenSession().get("loginUser");
    }

    /**
     * 获取当前APP登录用户的当前请求接口的数据范围（暂无数据范围）
     **/
    public static List<String> getLoginUserDataScope() {
        return CollectionUtil.newArrayList();
    }

    /**
     * 获取当前APP登录用户ID
     **/
    public static String getAppLoginUserId() {
        // 1.获取用户id
        SaBaseClientLoginUser saBaseClientLoginUser = getClientLoginUser();
        if(ObjectUtil.isEmpty(saBaseClientLoginUser) || ObjectUtil.isEmpty(saBaseClientLoginUser.getId())) {
            throw new CommonException("无法获取当前用户");
        }
        return saBaseClientLoginUser.getId();
    }
}
